import { playerMove, isMin } from "./play.js";
import showUI from "./ui.js";

showUI();

let over = false;

window.onkeydown = function (e) {
  if (over) return;

  let resule = false;
  if (e.key === "ArrowUp") {
    resule = playerMove("up");
  } else if (e.key === "ArrowDown") {
    resule = playerMove("down");
  } else if (e.key === "ArrowLeft") {
    resule = playerMove("left");
  } else if (e.key === "ArrowRight") {
    resule = playerMove("right");
  }

  if (resule) {
    showUI();
    if (isMin()) {
      over = true;
      alert("游戏胜利");
    }
  }
};
